/*
 * All right reserved@Raygo 2022~2030
 */

package com.raygo.runner.core.command;

import java.util.HashMap;
import java.util.Map;

/**
 * 命令执行结果
 *
 * @author Raygo
 * @since 2022年8月6日
 */
public class CmdResult {
    /**
     * 结果码，0为成功，其他为失败
     */
    private int code;
    /**
     * 错误信息
     */
    private String errorMsg;
    /**
     * 输出
     */
    private Map<String, Object> output;

    /**
     * 无参构造
     */
    public CmdResult() {
        this.code = 0;
    }

    /**
     * 有输出的构造
     *
     * @param output 输出
     */
    public CmdResult(Map<String, Object> output) {
        this.output = output;
    }

    /**
     * 有输出的结果
     *
     * @param key   键
     * @param value 值
     */
    public CmdResult(String key, Object value) {
        if (output == null) {
            output = new HashMap<>();
        }
        output.put(key, value);
    }

    /**
     * 错误码和信息构造
     *
     * @param code  错误码
     * @param error 错误信息
     */
    public CmdResult(int code, String error) {
        this.code = code;
        this.errorMsg = error;
    }

    /**
     * Get result code
     *
     * @return the result
     */
    public int getCode() {
        return code;
    }

    /**
     * Set result code
     *
     * @param result the code to set
     */
    public void setCode(int result) {
        this.code = result;
    }

    /**
     * Get errorMsg value
     *
     * @return the errorMsg
     */
    public String getErrorMsg() {
        return errorMsg;
    }

    /**
     * Set errorMsg to errorMsg
     *
     * @param errorMsg the errorMsg to set
     */
    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    /**
     * Get output value
     *
     * @return the output
     */
    public Map<String, Object> getOutput() {
        return output;
    }

    /**
     * Set output to output
     *
     * @param output the output to set
     */
    public void setOutput(Map<String, Object> output) {
        this.output = output;
    }
}
